package com.example.wufan.recyclerviewtest.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.wufan.recyclerviewtest.adaper.MyAdapter;
import com.example.wufan.recyclerviewtest.R;
import com.example.wufan.recyclerviewtest.adaper.TcaseAdapter;
import com.example.wufan.recyclerviewtest.bean.ArticleBean;
import com.example.wufan.recyclerviewtest.bean.TcaseBean;
import com.example.wufan.recyclerviewtest.iface.ArticleListener;
import com.example.wufan.recyclerviewtest.iface.TcaseListener;
import com.example.wufan.recyclerviewtest.model.ArticleModel;
import com.example.wufan.recyclerviewtest.model.TcaseModel;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
  private RecyclerView recyclerView;
    private  RecyclerView.LayoutManager layoutManager;
    private TcaseAdapter tcaseAdapter;
    private List<TcaseBean> list=null;
    //
    TcaseListener tcaseListener=new TcaseListener() {
        @Override
        public void onResponsse(List<TcaseBean> beanlist) {
            list=beanlist;
            tcaseAdapter.setList(list);
            tcaseAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();

        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();

        //实力化Articlemodel，调用方法获取网络数据
        TcaseModel tcaseModel=new TcaseModel();
        tcaseModel.getResultList("Tcase",2,"rv1l2tidbomann2qn86nln6ur2",tcaseListener);
    }

    private void initRecyclerView() {
        //获取recyclerview 设置属性 获取数据源 绑定
        recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
        //线性布局
        layoutManager=new LinearLayoutManager(this);
        //
        recyclerView.setLayoutManager(layoutManager);
        //
        recyclerView.setHasFixedSize(true);
        //
      //  list=getDate();
        tcaseAdapter=new TcaseAdapter(this);
        tcaseAdapter.setList(list);
        recyclerView.setAdapter(tcaseAdapter);
    }
/*
    //自定义 获取数据源并形成list
    private List<ArticleBean> getDate()
    {
        //定义list，复制返回
        List<ArticleBean> list=new ArrayList<ArticleBean>();
        ArticleBean articleBean;
        //1
        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("标题1");
        articleBean.setDescription("描述1");
        articleBean.setTime("2017-4-6");
        articleBean.setImgid(R.drawable.f1);
        list.add(articleBean);
        //2
        articleBean=new ArticleBean();
        articleBean.setArticleId(2);
        articleBean.setTitle("标题2");
        articleBean.setDescription("描述2");
        articleBean.setTime("2017-4-6");
        articleBean.setImgid(R.drawable.f2);
        list.add(articleBean);
        //3
        articleBean=new ArticleBean();
        articleBean.setArticleId(3);
        articleBean.setTitle("标题3");
        articleBean.setDescription("描述3");
        articleBean.setTime("2017-4-6");
        articleBean.setImgid(R.drawable.f3);
        list.add(articleBean);
        //4
        articleBean=new ArticleBean();
        articleBean.setArticleId(4);
        articleBean.setTitle("标题4");
        articleBean.setDescription("描述4");
        articleBean.setTime("2017-4-6");
        articleBean.setImgid(R.drawable.f4);
        list.add(articleBean);
        //5
        articleBean=new ArticleBean();
        articleBean.setArticleId(5);
        articleBean.setTitle("标题5");
        articleBean.setDescription("描述5");
        articleBean.setTime("2017-4-6");
        articleBean.setImgid(R.drawable.f5);
        list.add(articleBean);
        //6
        articleBean=new ArticleBean();
        articleBean.setArticleId(6);
        articleBean.setTitle("标题6");
        articleBean.setDescription("描述6");
        articleBean.setTime("2017-4-6");
        articleBean.setImgid(R.drawable.f6);
        list.add(articleBean);
        return list;
    }
    */
}

